package com.oss.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.users.User;

/**
 * @author xueqiang.mi
 * @date 2010-2-8
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Link implements Serializable {
	private static final long serialVersionUID = 4820985705733095892L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String name;
	@Persistent
	private String url;
	@Persistent
	private String source;
	@Persistent(serialized = "true", defaultFetchGroup = "true")
	private Text description;
	@Persistent
	private String author;
	@Persistent
	private String blog;
	@Persistent
	private User createdAuthor;
	@Persistent
	private Date createdDate = new Date();
	@Persistent
	private String prj = "notSet";
	@Persistent
	private String tag = "notSet";
	@Persistent
	private String topic = "notSet";
	@Persistent
	private Boolean enabled = true;
	@Persistent
	private Boolean frozen = false;
	@Persistent
	private Long view = 0L;
	@Persistent
	private Long vote = 0L;
	@NotPersistent
	private String str_desc;

	public Link() {
		super();
	}

	public String getAuthor() {
		return author;
	}

	public String getBlog() {
		return blog;
	}

	public User getCreatedAuthor() {
		return createdAuthor;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public String getDescription() {
		if (description != null) {
			return description.getValue();
		}
		return null;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public Boolean getFrozen() {
		return frozen;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getPrj() {
		return prj;
	}

	public String getSource() {
		return source;
	}

	public String getStr_desc() {
		return str_desc;
	}

	public String getTag() {
		return tag;
	}

	public String getTopic() {
		return topic;
	}

	public String getUrl() {
		return url;
	}

	public Long getView() {
		return view;
	}

	public Long getVote() {
		return vote;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public boolean isNew() {
		return (this.id == null);
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public void setBlog(String blog) {
		this.blog = blog;
	}

	public void setCreatedAuthor(User createdAuthor) {
		this.createdAuthor = createdAuthor;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public void setDescription(String description) {
		this.description = new Text(description);
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public void setFrozen(Boolean frozen) {
		this.frozen = frozen;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPrj(String prj) {
		this.prj = prj;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public void setStr_desc(String strDesc) {
		str_desc = strDesc;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setView(Long view) {
		this.view = view;
	}

	public void setVote(Long vote) {
		this.vote = vote;
	}

	@Override
	public String toString() {
		return "Link [id=" + id + ", name=" + name + "]";
	}

}
